﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sherwood.SignOn.Server.Models.Services;
using Sherwood.SignOn.Server.Controllers;
using Sherwood.SignOn.Server.Models.ViewModels;
using System.Web.Mvc;

namespace Sherwood.SignOn.Server.Tests.UserAccountTests
{
    [TestClass]
    public class RememberMeTests
    {
       /* [TestMethod]
        public void SetRememberMeOnAccountCreationTest()
        {
            //Arrange
            UserAccountController controller = new UserAccountController();
            RegisterViewModel model = new RegisterViewModel();
            model.UserName = "myUsername";
            model.Password = "myPassword";
            model.Password2 = "myPassword";
            model.FirstName = "John";
            model.LastName = "Smith";
            model.Email = "someemail@somewhere1234.com";
            model.CultureName1 = "en-US";
            model.CultureName2 = "en-US";
            model.CultureName3 = "en-US";
            model.DateOfBirth = new DateTime(2010, 1, 1);
            model.Gender = Gender.Male;
            model.Country = "US";
            model.RememberMe = true;

            //Act
            ViewResult result = controller.Register(model) as ViewResult;
            IUserAccount account = Data.UserAccounts.GetUserAccountByUsername(model.UserName);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(account.RememberMe);
        }

        [TestMethod]
        public void SetRememberMeFalseOnAccountCreationTest()
        {
            //Arrange
            UserAccountController controller = new UserAccountController();
            RegisterViewModel model = new RegisterViewModel();
            model.UserName = "myUsername";
            model.Password = "myPassword";
            model.Password2 = "myPassword";
            model.FirstName = "John";
            model.LastName = "Smith";
            model.Email = "someemail@somewhere1234.com";
            model.CultureName1 = "en-US";
            model.CultureName2 = "en-US";
            model.CultureName3 = "en-US";
            model.DateOfBirth = new DateTime(2010, 1, 1);
            model.Gender = Gender.Male;
            model.Country = "US";
            model.RememberMe = false;

            //Act
            ViewResult result = controller.Register(model) as ViewResult;
            IUserAccount account = Data.UserAccounts.GetUserAccountByUsername(model.UserName);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsFalse(account.RememberMe);
        }

        [TestMethod]
        public void SignInAndSetRememberMeTest()
        {
            //Assemble
            IUserAccount user = TestHelper.CreateVerifiedDummyUser("username", "password");
            
            
            //Act
            SignInViewModel viewModel = new SignInViewModel();
            viewModel.UserName = "username";
            viewModel.Password = "password";
            viewModel.RememberMe = true;
            viewModel.ClientSessionId = Guid.NewGuid().ToString();
            viewModel.ReturnUrl = "http://somewhere.sherwood.codeplex.com/SignIn/?ReturnUrl=bogus&ticket={signinticket}&signature={signinsignature}";
            viewModel.SignOutUrl = "http://somewhere.sherwood.codeplex.com/SignOut/?ticket={signoutticket}&signature={signoutsignature}";
            SignInController controller = new SignInController();
            RedirectResult result = controller.Index(viewModel) as RedirectResult;
            user = Data.UserAccounts.GetUserAccountByUsername(viewModel.UserName); //retrieve latest version of user


            //Assert
            Assert.IsTrue(user.RememberMe);

        }

        [TestMethod]
        public void SignInAndSetRememberMeFalseTest()
        {
            //Assemble
            IUserAccount user = TestHelper.CreateVerifiedDummyUser("username", "password");


            //Act
            SignInViewModel viewModel = new SignInViewModel();
            viewModel.UserName = "username";
            viewModel.Password = "password";
            viewModel.RememberMe = false;
            viewModel.ClientSessionId = Guid.NewGuid().ToString();
            viewModel.ReturnUrl = "http://somewhere.sherwood.codeplex.com/SignIn/?ReturnUrl=bogus&ticket={signinticket}&signature={signinsignature}";
            viewModel.SignOutUrl = "http://somewhere.sherwood.codeplex.com/SignOut/?ticket={signoutticket}&signature={signoutsignature}";
            SignInController controller = new SignInController();
            RedirectResult result = controller.Index(viewModel) as RedirectResult;
            user = Data.UserAccounts.GetUserAccountByUsername(viewModel.UserName); //retrieve latest version of user


            //Assert
            Assert.IsFalse(user.RememberMe);

        }*/

    }
}
